/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package rentcalculator.model;

import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

/**
 *
 * @author K.E.Y
 */
@Entity
public class Bill {
    @Id
    @GeneratedValue(strategy = IDENTITY)
    private long id;
    private String name;
    private Date start;
    private Date end;
    
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name="facility_id")
    private Facility facility;
    
    private double price;
    private String currency;

    public Bill() {
    }
    
    public Bill( String name, Date start, Date end, Facility facility, double price, String currency) {
        this.name = name;
        this.start = start;
        this.end = end;
        this.facility = facility;
        this.price = price;
        this.currency = currency;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getCurrency() {
        return currency;
    }

    public void setCurrency(String currency) {
        this.currency = currency;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getStart() {
        return start;
    }

    public void setStart(Date start) {
        this.start = start;
    }

    public Date getEnd() {
        return end;
    }

    public void setEnd(Date end) {
        this.end = end;
    }

    public Facility getFacility() {
        return facility;
    }

    public void setFacility(Facility facility) {
        this.facility = facility;
    }
    
    public double getActualPrice(){
        List<Discount> discounts = this.facility.getBillDiscounts();
        double actualPrice = this.getPrice();
        if(discounts == null ) return actualPrice;
        Iterator<Discount> iter = discounts.iterator();
        while(iter.hasNext()){
            Discount tmp = iter.next();
            actualPrice = tmp.discount(actualPrice);
            
            
            
        }
        
        return actualPrice;
        
    }
  }
